#!/bin/bash


echo -e "可用镜像源：\n 1.清华镜像源 \n 2.中科大镜像源(默认) \n 3.腾讯云镜像源 \n 4.阿里云镜像源  \n 5.网易镜像源 \n 6.荆楚理工学院 \n 7.南阳理工学院镜像源"


read -p '请选择镜像源:' choose

Change_the_mirror_source(){
        echo 使用$1 镜像源

        echo '备份旧的yum源文件'
        mkdir -p /etc/yum.repos.d/bak
        mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak/
        # 运行命令
        `$2`
        echo '清理缓存'
        yum clean all
        echo '重新构建缓存'
        yum makecache
}

# 判断系统架构


if [ $(uname -m) == 'x86_64' ];then

    echo '当前系统架构为X86_64'
    # X86_64架构

    case $choose in
        1)
            Change_the_mirror_source "清华镜像源" "curl -o /etc/yum.repos.d/Centos7-tuna.repo https://mirrors.wlnmp.com/centos/Centos7-tuna-x86_64.repo"
            ;;
        2)
            Change_the_mirror_source "使用中科大镜像源" "curl -o /etc/yum.repos.d/Centos7-ustc.repo https://mirrors.wlnmp.com/centos/Centos7-ustc-x86_64.repo"
            ;;
        3)
            Change_the_mirror_source "腾讯云像源" "curl -o /etc/yum.repos.d/Centos7-tencent.repo https://mirrors.wlnmp.com/centos/Centos7-tencent-x86_64.repo"
            ;;
        4)
            Change_the_mirror_source "阿里云像源" "curl -o /etc/yum.repos.d/Centos7-aliyun.repo https://mirrors.wlnmp.com/centos/Centos7-aliyun-x86_64.repo"
            ;;
        5)
            Change_the_mirror_source "网易像源" "curl -o /etc/yum.repos.d/Centos7-163.repo https://mirrors.wlnmp.com/centos/Centos7-163-x86_64.repo"
            ;;
        6)
            Change_the_mirror_source "荆楚理工学院像源" "curl -o /etc/yum.repos.d/Centos7-jcut.repo https://mirrors.wlnmp.com/centos/Centos7-jcut-x86_64.repo"
            ;;
        7)
            Change_the_mirror_source "南阳理工学院像源" "curl -o /etc/yum.repos.d/Centos7-nyist.repo https://mirrors.wlnmp.com/centos/Centos7-nyist-x86_64.repo"
            ;;
        *)
            echo '输入错误'
            exit 1
            ;;
    esac



# 其他架构
else
    echo 当前系统架构为$(uname -m)

        case $choose in
        1)
            Change_the_mirror_source "清华镜像源" "curl -o /etc/yum.repos.d/Centos7-tuna.repo https://mirrors.wlnmp.com/centos/Centos7-tuna-altarch.repo"
            ;;
        2)
            Change_the_mirror_source "使用中科大镜像源" "curl -o /etc/yum.repos.d/Centos7-ustc.repo https://mirrors.wlnmp.com/centos/Centos7-ustc-altarch.repo"
            ;;
        3)
            Change_the_mirror_source "腾讯云像源" "curl -o /etc/yum.repos.d/Centos7-tencent.repo https://mirrors.wlnmp.com/centos/Centos7-tencent-altarch.repo"
            ;;
        4)
            Change_the_mirror_source "阿里云像源" "curl -o /etc/yum.repos.d/Centos7-aliyun.repo https://mirrors.wlnmp.com/centos/Centos7-aliyun-altarch.repo"
            ;;
        5)
            Change_the_mirror_source "网易像源" "curl -o /etc/yum.repos.d/Centos7-163.repo https://mirrors.wlnmp.com/centos/Centos7-163-altarch.repo"
            ;;
        6)
            Change_the_mirror_source "荆楚理工学院像源" "curl -o /etc/yum.repos.d/Centos7-jcut.repo https://mirrors.wlnmp.com/centos/Centos7-jcut-altarch.repo"
            ;;
        7)
            Change_the_mirror_source "南阳理工学院像源" "curl -o /etc/yum.repos.d/Centos7-nyist.repo https://mirrors.wlnmp.com/centos/Centos7-nyist-altarch.repo"
            ;;
        *)
            echo '输入错误'
            exit 1
            ;;
    esac

fi

    echo '配置完成'